import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '../components/loginView/login.vue'
import Menu from '../components/menuView/menu.vue'
import Company from '../components/salary/company.vue'
import Kehu from '../components/user/user.vue'
import axios from 'axios'
import User from '../components/salary/user.vue'
import Account from '../components/loginView/account.vue'
import Phone from '../components/loginView/phone.vue'
import Selfappt from '../components/self/Selfappt.vue'
import Selford from '../components/self/selford.vue'
import Selfsalrecord from '../components/self/selfsalrecord.vue'
import Emp from '../components/EmpView/emp.vue'

import moment from "moment";
import store from '../store'
import Log from '../components/log/log.vue'
import Center from '../components/percenter/center.vue'
//时间转换（使用monent插件）
Vue.prototype.$moment = moment;
Vue.filter("dateformat", function(value, formatString) {
  formatString = formatString || "YYYY-MM-DD";
  // return moment(value).format(formatString);
  return moment(value).format(formatString); // 这是时间戳转时间
});

import House from '../components/HouseView/House.vue'
import Report from '../components/ReportView/Report.vue';
import EverAppointment from '../components/salCenter/EverAppointment.vue'
import ManagerOrder from '../components/salCenter/order.vue'
import SalRecord from '../components/salCenter/SalRecord.vue'

import ErDistribution from '../components/permissionView/erDistribution.vue';
import RpDistribution from '../components/permissionView/rpDistribution.vue';
Vue.use(VueRouter)
Vue.prototype.$axios=axios;



const routes = [
  
  {
    path: '/Login',
    name: 'Login',
    component: Login,
    children: [
      {
        path: '/Account',
        name: 'Account',
        component: Account
      },
      {
        path: '/Phone',
        name: 'Phone',
        component: Phone
      },
    
    ]
  },
  
  {
    path: '/Menu',
    name: 'Menu',
    component: Menu,
    children: [
      //财务管理
      {
        path: '/Company',
        name: 'Company',
        component: Company
      },
      {
        path: '/User',
        name: 'User',
        component: User
      },
      {
        path: '/Kehu',
        name: 'Kehu',
        component: Kehu
      },
      {
        path: '/EverAppointment',
        name: 'EverAppointment',
        component: EverAppointment
      },
      {
        path: '/ManagerOrder',
        name: 'ManagerOrder',
        component: ManagerOrder
      },
      {
        path: '/SalRecord',
        name: 'SalRecord',
        component: SalRecord
      },
      {
        path: '/ErDistribution',
        name: 'ErDistribution',
        component: ErDistribution
      },
      {
        path: '/RpDistribution',
        name: 'RpDistribution',
        component: RpDistribution
      }
    
    ]
  },
  {
    path: '/',
    name: 'Menu',
    component: Menu,
    children: [
      {
        path: '/House',
        name: 'House',
        component: House
      },
    ],
  },
  {
    path: '/',
    name: 'Menu',
    component: Menu,
    children: [
      {
        path: '/Report',
        name: 'Report',
        component: Report
      },
    ],
  },
 

  {
    path: '/Menu',
    name: 'Menu',
    component: Menu,
    children: [
      {
        path: '/Emp',
        name: 'Emp',
        component: Emp
      },

      // 我的置业中心
      {
        path: '/Selfappt',
        name: 'Selfappt',
        component: Selfappt
      },
      {
        path: '/Selford',
        name: 'Selford',
        component: Selford
      },
      {
        path: '/Selfsalrecord',
        name: 'Selfsalrecord',
        component: Selfsalrecord
      },
      {
        path: '/Log',
        name: 'Log',
        component: Log
      },
      {
        path: '/Center',
        name: 'Center',
        component: Center
      }
      , 
    
    ]
  },

]



const router = new VueRouter({
  // mode: 'history',
  
  base: process.env.BASE_URL,
  routes
})



// 导航守卫
// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
// to：这是你要跳去的路由对象。
// from：这是你要离开的路由对象。
// next：是一个方法，它接受参数。
  router.beforeEach((to, from, next) => {
   
  if (to.path ==='/Account'||to.path ==='/Phone') {
    next();  
  } else{
    let loginResult = localStorage.getItem('Authorization');
 
    if(loginResult==='false'||loginResult===''||loginResult=='undefined') {
    
      next('/Account');   
    } else {
      
      next();
    }
  }
});

export default router
